package com.example.shiwu.service;

import com.example.shiwu.db.dao.ReceiveDao;
import com.example.shiwu.db.dao.base.BaseDaoFactory;
import com.example.shiwu.db.model.Receive;
import com.example.shiwu.manager.DatabaseHelper;

import java.util.ArrayList;
import java.util.List;

public class ReceiveService {

    private DatabaseHelper dbHelper;
    private ReceiveDao<Receive> ReceiveDao;
    private ArrayList<Receive> listReceive = new ArrayList<>();

    private static final int PAGE_SIZE = 10;
    private static final int TOTAL_PAGE = 0;



    /**获取单个数据
     * @param receive
     * @return
     */
    public List<Receive> getReceive(Receive receive) {
        listReceive = new ArrayList<>();
        ReceiveDao = BaseDaoFactory.getInstance().createBaseDao(ReceiveDao.class, Receive.class);
        listReceive.addAll(ReceiveDao.query(receive));
        return listReceive;
    }

    /**分页获取数据
     * @param receive
     * @return
     */
    public List<Receive> getReceiveList(Receive receive,Integer startIndex,Integer limit) {
        ReceiveDao = BaseDaoFactory.getInstance().createBaseDao(ReceiveDao.class, Receive.class);
        listReceive = new ArrayList<>();
        listReceive.addAll(ReceiveDao.query(receive,null,"create_time desc",null,startIndex,limit));
        return listReceive;
    }

    public boolean save(Receive receive) {
        ReceiveDao = BaseDaoFactory.getInstance().createBaseDao(ReceiveDao.class, Receive.class);
        long size = ReceiveDao.insert(receive);
        if(size >0 ){
            return true;
        }
        return false;
    }

    public boolean updade(Receive Receive,Receive where) {
        ReceiveDao = BaseDaoFactory.getInstance().createBaseDao(ReceiveDao.class, Receive.class);

        long size = ReceiveDao.update(Receive,where);
        if(size >0 ){
            return true;
        }
        return false;
    }
}
